package com.veryGood.controller;

import com.veryGood.common.result.R;
import com.veryGood.common.result.Res;
import com.veryGood.domain.pojo.EmployeeInfo;
import com.veryGood.service.EmployeeManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 员工管理
 *
 */
@Controller
public class EmployeeManageController {
    @Autowired
    EmployeeManageService emp;

    @RequestMapping(value = "/addEmployee")
    @ResponseBody
    public R addEmployee(@RequestBody EmployeeInfo empDto){
        System.out.println(empDto.toString());
        empDto.setStatus(1);
        empDto.setUserId(1);
        return emp.addEmployee(empDto);
    }
    @RequestMapping(value = "/delEmployee")
    @ResponseBody
    public R delEmployee(Integer userId){
        return emp.delEmployee(userId);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Res searchAll(){
        List<EmployeeInfo> list = emp.allEmployee();
        if (!list.isEmpty()) {
            // 构造返回的数据对象，包含code、msg、count和data字段
            Res res = new Res();
            res.setCode(0); // 设置code字段值
            res.setMsg("成功"); // 设置msg字段值
            res.setCount(list.size()); // 设置count字段值
            res.setData(list); // 设置data字段值
            return Res.success(list);
        } else {
            // 如果没有数据，则返回相应的错误信息
            return Res.error("无数据");
        }
    }
}
